import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
    // 一级路由
    {
      path: '/home',
      name:'home',
      component:()=> import('@/views/home/index.vue'),
      children: [
        // 二级路由
        // 热门推荐
        {
          path:'recmusic',
          name:'recmusic',
          component: ()=> import('@/views/home/recmusic/index.vue'),
        },
        // 热歌榜(热门榜单)
        {
          path:'hotmusic',
          name:'hotmusic',
          component: ()=> import('@/views/home/hotmusic/index.vue'),
          // 三级路由
          children: [
            {
              path: 'toplist/:id',
              name: 'toplist',
              component: ()=> import('@/components/top-list.vue'),
            }
          ]
        },
         // 热歌榜
         {
          path:'searchmusic',
          name:'searchmusic',
          component: ()=> import('@/views/home/searchmusic/index.vue'),
        },
      ]
    },
    {
      path: '/hot',
      name:'hot',
      component:()=> import('@/views/hot/index.vue'),
    },
    {
      path: '/search',
      name:'search',
      component:()=> import('@/views/search/index.vue'),
    },
    {
      path: '/songlist',
      name:'songlist',
      component:()=> import('@/views/songlist/index.vue'),
    },
    {
      path: '/lyric',
      name:'lyric',
      component:()=> import('@/views/lyric/index.vue'),
    },
    {
      path: '/songdetail',
      name:'songdetail',
      component:()=> import('@/views/songdetail/index.vue'),
    },
    {
      path:'/',
      redirect:'/home/recmusic'
    },
    {
      path:'*',
      component:()=> import('@/views/error/index.vue'),
    }
]

const router = new VueRouter({
  routes,
  // 设置 router-link 组件点击高亮（激活时高亮）
  // linkExactActiveClass: "active"
})


//防止重复点击导航时，控制台报错，添加以下代码
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
export default router
